#include "alglib_util.h"

VALUE real1d_to_array(ap::real_1d_array *x) {
    VALUE ar=rb_ary_new2(x->gethighbound()-x->getlowbound());
    for(uint i=x->getlowbound();i<=x->gethighbound();i++) {
        rb_ary_push(ar,rb_float_new(x->operator()(i)));
    }
    return ar;
}

void array_to_real1d(VALUE ary, ap::real_1d_array *x) {
    x->setlength(RARRAY_LEN(ary));
    //std::cout << "Largo:" << RARRAY_LEN(ary) << "\n";
    for(long i=0;i<RARRAY_LEN(ary);i++) {
      //  std::cout << "i:" << i << "=" <<  rb_num2dbl(RARRAY_PTR(ary)[i]) <<"\n";
        x->operator()(i)=rb_num2dbl(RARRAY_PTR(ary)[i]);
    }
}
